<html>
  <head>
    <title>Developing an Xpo.UpdateSchema provider</title>
    <link rel="stylesheet" type="text/css" href="../../styles/presentation.css" />
    <link rel="stylesheet" type="text/css" href="ms-help://Hx/HxRuntime/HxLink.css" />
    <script type="text/javascript" src="../../scripts/EventUtilities.js"></script>
    <script type="text/javascript" src="../../scripts/SplitScreen.js"></script>
    <script type="text/javascript" src="../../scripts/Dropdown.js"></script>
    <script type="text/javascript" src="../../scripts/script_loc.js"></script>
    <script type="text/javascript" src="../../scripts/script_manifold.js"></script>
    <script type="text/javascript" src="../../scripts/script_feedBack.js"></script>
    <script type="text/javascript" src="../../scripts/CheckboxMenu.js"></script>
    <script type="text/javascript" src="../../scripts/CommonUtilities.js"></script>
  </head>
  <body>
    <input type="hidden" id="userDataCache" class="userDataStyle" />
    <input type="hidden" id="hiddenScrollOffset" />
    <img id="collapseImage" style="display:none; height:0; width:0;" src="../../icons/collapse_all.gif" title="Collapse image" />
    <img id="expandImage" style="display:none; height:0; width:0;" src="../../icons/expand_all.gif" title="Expand Image" />
    <img id="collapseAllImage" style="display:none; height:0; width:0;" src="../../icons/collapse_all.gif" />
    <img id="expandAllImage" style="display:none; height:0; width:0;" src="../../icons/expand_all.gif" />
    <img id="dropDownImage" style="display:none; height:0; width:0;" src="../../icon/dropdown.gif" />
    <img id="dropDownHoverImage" style="display:none; height:0; width:0;" src="../../icons/dropdownHover.gif" />
    <img id="copyImage" style="display:none; height:0; width:0;" src="../../icons/copycode.gif" title="Copy image" />
    <img id="copyHoverImage" style="display:none; height:0; width:0;" src="../../icons/copycodeHighlight.gif" title="CopyHover image" />
    <div id="header">
      <table id="topTable" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <span onclick="ExpandCollapseAll(toggleAllImage)" style="cursor:default;" onkeypress="ExpandCollapseAll_CheckKey(toggleAllImage, event)" tabindex="0">
              <img ID="toggleAllImage" class="toggleAll" src="../../icons/collapse_all.gif" />
              <label id="collapseAllLabel" for="toggleAllImage" style="display: none;">Collapse All</label>
              <label id="expandAllLabel" for="toggleAllImage" style="display: none;">Expand All</label>
            </span>
          </td>
        </tr>
      </table>
      <table id="bottomTable" cellpadding="0" cellspacing="0">
        <tr id="headerTableRow1">
          <td align="left">
            <span id="runningHeaderText">DevExpress Contrib</span>
          </td>
        </tr>
        <tr id="headerTableRow2">
          <td align="left">
            <span id="nsrTitle">
                  Developing an Xpo.UpdateSchema provider
               </span>
          </td>
          <td align="center" style="width: 1px; padding: 0px">
            <img src="../../images/DevExContrib 32.png" alt="DevExpress Contrib" />
          </td>
        </tr>
        <tr id="headerTableRow3">
          <td align="left">
            <span id="headfb" class="feedbackhead" />
          </td>
        </tr>
      </table>
      <table id="gradientTable">
        <tr>
          <td class="nsrBottom" background="../../icons/gradient.gif" />
        </tr>
      </table>
    </div>
    <div id="mainSection">
      <div id="mainBody">
        <div class="Content">
          <p>Implementing an UpdateSchema provider is relatively simple. Implement the IUpdateSchemaProvider
          interface, add a constructor with a specific signature and, optionally, add one static method.</p>
          <p>The update schema provider class must be decorated with an UpdateSchemaProvider attribute. The parameter
          is the XpoProviderTypeString for the XPO connection provider.</p>
          <pre lang="cs" numberLines="true" outlining="true" title="Using the UpdateSchemaProvider attribute">
    [UpdateSchemaProvider(AccessConnectionProvider.XpoProviderTypeString)]
    public class AccessUpdateSchemaProvider : IUpdateSchemaProvider
    {
    }</pre>
          <p>The provider must have a constructor with a ConnectionString parameter. This connection string
          is the same connection string that you would use to connect to the XPO DataLayer or the XPO Session.</p>
          <pre lang="cs" numberLines="true" outlining="true" title="Microsoft Access provider constructor">
   private OleDbConnection connection;
   public AccessUpdateSchemaProvider(string connectionString)
   {
      ConnectionString = UpdateSchemaProviderHelper.RemoveXpoProviderTypeParameter(connectionString);
      connection = new OleDbConnection();
    }</pre>
          <p>Notice in the constructor that the connection is not opened here. Opening the connection should be
          performed in the Open() method.</p>
          <p>The first parameter of each main functionality method (ModifyStringColumnSize, RenameColumn, DeleteColumn)
          is an UpdateSchemaOrder. This allows the provider to perform the functionality either before or after the XPO
          Schema Update. In fact you can implement a portion of the functionality before and another portion after the
          XPO Schema Update. Most of the time the RenameColumn will be done before the XPO Schema Update and the
          ModifyStringColumnSize and DeleteColumn will be done after the XPO Schema Update.</p>
          <p>The additional static method DropDatabase is used during unit testing and may be useful in other instances
          This is a method is provided so that unit testing can run from a clean starting point. The DropDatabase method
          for the Microsoft Access provider is as follows:</p>
          <pre lang="cs" numberLines="true" outlining="true" title="Microsoft Access provider DropDatabase method">
   public static bool DropDatabase(string connectionString)
   {
      return FileBasedProviderHelper.DropDatabase(connectionString);
   }</pre>
          <p>This method uses a provider helper for file based providers. Both the Microsoft Access and VistaDB 3
          providers are file based and use this static helper class.</p>
          <p>All providers (apart from Microsoft SQL Server and Microsoft Access) should be placed in
          the DevExpressContrib.Xpo.UpdateSchema.Providers project.</p>
          <p>You may, of course, use the current providers to help jump start creating a new provider. Both the
          Microsoft SQL Server provider and the VistaDB 3 provider took me a couple of hours to code up and test.
          The Microsoft Access provider took me a bit longer because RenameColumn was not a simple SQL statement.
          I imagine that a database which does not support renaming a column would take a few additional hours. It
          would probably have to be coded as a create new column, copy data from old column and then drop the old
          column.</p>
          <p>If you write a provider for one of the databases that XPO supports, please consider contributing it to
          DevExpress Contrib.</p>
          <p>&nbsp;</p>
          <p>
            <a href="../Task-Based Help.html">Back to task-based help.</a>
          </p>
        </div>
      </div>
      <div id="footer">
        <div class="footerLine">
          <img width="100%" height="3px" src="../../icons/footer.gif" title="Footer image" />
        </div>
        <p />
        <div id="DevLynxVersion">
           <p><small>v2009.0.3332.39062 (2009-02-14  21:42:04)</small></p>
        </div>
        <div id="DevLynxCopyright">
           <p>Copyright &copy; 2008-2009, DevLynx</p>
        </div>
      </div>
    </div>
  </body>
</html>
<!-- @SortOrder 2 -->
